import { fetchLogin, fetchLoginOut, fetchGetCheckCode, fetchModifyPassword } from '../../fetch/modules/login'

const state = {
    LoginPage: {
    },
    loginOut: {},
    codeInfo: {},
    passwordResult: {}
}

const actions = {
    GET_LOGIN: ({ commit, state }, opt) => {
        return fetchLogin(opt).then(loginpage => commit('GET_LOGIN_DATA', { loginpage }))
    },
    LOGIN_OUT: ({ commit, state }, opt) => {
        return fetchLoginOut(opt).then(loginout => commit('LOGIN_OUT_IFNO', { loginout }))
    },
    MODIFY_PASSWORD: ({ commit, state }, opt) => {
      return fetchModifyPassword(opt).then(info => commit('MODIFY_PASSWORD', { info }))
    },
    FETCH_CHECK_CODE: ({ commit, state }, opt) => {
        return fetchGetCheckCode(opt).then(code => commit('GET_CHECK_CODE', { code }))
    }
}
const mutations = {
    GET_LOGIN_DATA: (state, { loginpage }) => {
        state.LoginPage = loginpage.data;
    },
    LOGIN_OUT_IFNO: (state, { loginout }) => {
        state.loginOut = loginout.data;
    },
    MODIFY_PASSWORD: (state, { info }) => {
      state.passwordResult = info.data;
  },
    GET_CHECK_CODE: (state, { code }) => {
        state.codeInfo = code.data;
    },
}

const getters = {
    getLoginData(state) {
        console.log('getters state');
        return state.LoginPage;
    },
    getLoginOutInfo(state) {
        return state.loginOut;
    },
    getModifyPasswordInfo(state){
      return state.passwordResult
    },
    getCheckCode(state) {
        return state.codeInfo;
    }
}

export default {
    state,
    actions,
    mutations,
    getters
}
